var newUserCoupon=({
	hadShareLog : function (phone){
		$.ajax({
			type: "POST",
			dataType: "json",
			url: "../sharePrize/hadShareLog.do?rnd="+ Math.random(),
			data : {phone :phone},
			success: function(data){
				if(data.msg=="needtoshare"){
					$("#phone_input").hide();
					$("#needshare").show();
					$("#share").show();
					$("#needget").hide();
				}else if(data.msg=="shared"){
					$("#isShare").val("share");
					$("#phone").show();
					$("#save").show();
					$("#needshare").hide();
					$("#share").hide();
				}else if(data.msg=="noregister"){
					$$.alert("您尚未是蓝居用户，快前往注册吧", function(){
						 window.location.href="./register.html?url="+encodeURIComponent(window.location.href);
						});
				}else{
					$("#hadshare").show();
					$("#share").hide();
				}
			},
			error: function(e) {
				$$.toast("请求出错");
			}
		});
	},
	getUserInfo : function (){
		if(phone ==""){
			$$.alert("您尚未登录，请登录再领取吧", function(){
				 window.location.href="./login.html?url="+encodeURIComponent(window.location.href);
				});
		}
		$.ajax({
			type : "POST",
			dataType : 'json',
			url : "../user/isLogin.do",
			data : {
			},
			success : function(data) {
				if(data.success){
				}
			}
		});
		
	},
	loginBtn : function (){
		var phone= $("#login_phone").val(),
		password= $("#password").val();
	if( !phone ){
		$$.toast("请输入手机号码");
		return ;
	}
	if( !password ){
		$$.toast("请输入密码");
		return;
	}
	$$.showPreloader("登陆中");
	$.ajax({
		type : "POST",
		dataType : 'json',
		url : "../login/ljLogin.do",
		data : {
			"phone": phone,
			"password": password,
		},
		success : function(data) {
			$$.hidePreloader();
			if( data.resultCode=="0" && data.content){
				$("#needshare").show();
				$("#share").show();
				$("#needget").show();
				$("#needlogin").hide();
//				$("#login_phone").hide();
//				$("#password").hide();
				$("#phone_input").hide();
				$("#login_btn").hide();
				$("#needget").hide();
				$("#hadshare").hide();
				$("#phone").val(data.content.phone);
				$("#u_phone").val(data.content.phone);
				$("#user_accounts").val("【用户："+data.content.phone.substring(0,3)+"*****"+data.content.phone.substring(8,11)+"】");
				newUserCoupon.hadShareLog(data.content.phone);
			}else if(data.content==1){
				$$.alert(data.msg, function(){
					 window.location.href="./register.html?url="+encodeURIComponent(window.location.href);
				});
			}
		},
		error: function(){
			$$.hidePreloader();
			$$.toast("登陆出错");
		}
	});
	},
	inserShareLog : function (){
		$.ajax({
			type: "POST",
			dataType: "json",
			url: "../sharePrize/inserShareLog.do?rnd="+ Math.random(),
			data : {phone :$("#u_phone").val()},
			success: function(data){
				if(data.success){
					console.log("分享成功");
					$("#share").hide();
				}else{
					$$.toast("分享失败");
				}
			},
			error: function(e) {
			}
		});
	},
	saveprize : function (){
		$.ajax({
			type: "POST",
			dataType: "json",
			url: "../sharePrize/inserSharePrize.do?rnd="+ Math.random(),
			data : {phone :$("#phone").val()},
			success: function(data){
				console.log(data);
				if(data.success){
					$$.toast("领取成功");
					$("#hadshare").show();
					$("#phone").hide();
					$("#save").hide();
				}else{
					$$.toast("领取失败，请稍后重试");
				}
			},
			error: function(e) {
			}
		});
	},
	toregiter : function (){
		 window.location.href="./register.html?url="+encodeURIComponent(window.location.href);
	}
});
$(function() {
	if(phone!="null"){
		$.ajax({
			type : "POST",
			dataType : 'json',
			url : "../user/isLogin.do",
			data : {
				phone : phone
			},
			success : function(data) {
				if(data.success){
					$("#user_accounts").text("【用户："+data.user.phone.substring(0,3)+"*****"+data.user.phone.substring(8,11)+"】");
					$("#u_phone").val(data.user.phone);
					$("#phone").val(data.user.phone);
					$("#phone_input").hide();
					$("#needget").show();
					newUserCoupon.hadShareLog(data.user.phone);
					
				}else{
					$("#needlogin").show();
					$("#login_phone").show();
					$("#password").show();
					$("#phone_input").show();
					$("#login_btn").show();
					$("#phone_input").show();
				}
			}
		});
	}else{
		$("#needlogin").show();
		$("#login_phone").show();
		$("#password").show();
		$("#phone_input").show();
		$("#login_btn").show();
		$("#phone_input").show();
	}


	$("#share").click(function (event){
		$$.alert("请点击右上角分享再领取吧", function(){
		});
	})
}); 
